<?php

namespace App\Listeners;

use DateTime;
use Illuminate\Database\Events\QueryExecuted;

class DBSqlListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param QueryExecuted $event
     * @return void
     */
    public function handle(QueryExecuted $event)
    {
//        Log::info("db sql");
//        $sql = $event->sql;
//        $bindings = $event->bindings;
//        $time = $event->time;//毫秒
//        $bindings = array_map(function ($binding) {
//            if (is_string($binding)) {
//                return "'$binding'";
//            } else {
//                if ($binding instanceof DateTime) {
//                    return $binding->format("'Y-m-d H:i:s'");
//                }
//                if ($binding === false) {
//                    return 0;
//                }
//                if ($binding === true) {
//                    return 1;
//                }
//            }
//            return $binding;
//        }, $bindings);
//
//        $sql = str_replace('?', '%s', $sql);
//        if ($time > 2000) {
//                Log::error('sql_log', ['sql' => $sql, 'time' => $time, "bindings" => $bindings]);
//        }
//            Log::error('sql_log', ['sql' => $sql, 'time' => $time, "bindings" => $bindings]);


    }
}
